<template>
  <div id="app" :class="$store.state.isTrue ? '' : 'has-nav'">

    <div v-if="!$store.state.isTrue">
      <van-nav-bar
      :class="ispabar ? 'van-nav-bar-pa' : 'van-nav-bar2'"
        :title="$store.state.title"
        :left-arrow="$store.state.hasArrow"
       
        @click-left="clickLeft"
        @click-right="clickRight"
        fixed
      >

        <!-- <template slot="right">
          <van-icon name="" size="18" />
        </template> -->
      </van-nav-bar>
      
    </div>

    <keep-alive>
      <router-view
        :key="$route.path"
        v-if="$route.meta.keepAlive"
      ></router-view>
    </keep-alive>
    <router-view :key="$route.path" v-if="!$route.meta.keepAlive"></router-view>

    
  </div>
</template>

<script>
import store from "./store/index";
import { is_weixin } from "./utils/common.js";
export default {
  name: "app",
  data() {
    return {
      ispabar : false,
      path: "",
      title: "",
    };
  },
   created() {
      if(process.env.VUE_APP_DEFAULT_PAGE == "/palogin"){
        if(window.webkit){
          this.ispabar =  true
        } else{
          this.ispabar =  false
        }
      }else{
          this.ispabar =  false
      }
      console.log("App 执行 getToken")
      // await getToken()
      
  },

  methods: {
    //监听页面最上方返回按钮

    clickLeft() {
      const path = this.$route.path;

      if (window.jsListener) {
        window.jsListener.doBack();
        path = "null";
      }

      //ios 交互 微信也有交互 多做判断

      if (is_weixin) {
        //如果是微信执行的操作
      } else {
        //如果不是微信执行的操作
        if (window.webkit) {
          if (window.webkit.messageHandlers) {
            if (window.webkit.messageHandlers.doBack) {
              window.webkit.messageHandlers.doBack.postMessage("");
              path = "null";
            }
          }
        }
      }
      switch (path) {
          // 平安专属
          case "/login":
          case "/index":
          case "/my":
          case "/couponactivity":
          case "/palogin":
            if(this.$store.state.envCode && this.$store.state.envCode == "qyb"){
              if (window.Android) {
                    window.Android.postMessage(JSON.stringify({
                      targetName:"Eqb",
                      actionName:"goBackNative",
                      data:{},
                      callback:{
                        success:""
                      }
                }))}else if(window.webkit){
                window.webkit.messageHandlers.EQBNative.postMessage(JSON.stringify({
                    targetName:"Eqb",
                          actionName:"goBackNative",
                          data:{},
                          callback:{
                            success:""
                          }
              }))}
            }
            break;
          // 我的考试
          case "/Train/ExExam":
            this.$router.go(-1);
            break;
          // 开始考试
          case "/Train/StartExam":
            this.$router.go(-1);
            break;
          // 考试说明
          case "/Train/ExExamExplain":
            this.$router.go(-1);
            break;
          // 考试结果
          case "/Train/ExamResult":
            this.$router.go(-1);
            break;
          default:
            if (window.history.length <= 2) {
              this.$router.push("/index");
            } else {
              this.$router.go(-1);
            }
            break;
        }
    },
    clickRight(){
      this.$router.push("/message");
    }
  },
};
</script>
<style lang="less" >
#app {
 
}
 .van-nav-bar2 {
    z-index: 10;
    padding-top: 0rem;
  }  
.van-nav-bar-pa {
    z-index: 10;
    padding-top: 0.5rem;
  }
.has-nav {
  padding-top: 45px;
}
</style>>


